Skip to content

Conversation

@abdelhamiderrahmouni
Copy link

[WIP]
One of the most hot runtimes nowadays is bun, it is fast, reliable and for me i really need it my projects.

I have tried integrating it with vitodeploy and it works. But I am stuck in one problem I could not solve yet, which has to do with starting, pausing, and restarting the worker that launches the bun start script.
when i start it it stays in starting state, when i pause it same, and when i restart it it fails.

I would love to have some help from the interested folks here !
Thanks in advance ❤️

@mjsarfatti
Copy link

I'd love bun support! I haven't tested your PR yet, but have you tried removing the '&' from

$command = __('bun --bun run --cwd :path start &', [
?

@abdelhamiderrahmouni
Copy link
Author

Yes i have, the command at first was running without & and had the same problem. I have added it to try and solve the problem but didn't work.

@abdelhamiderrahmouni
Copy link
Author

Another thing i did't mention before is about deployments, they fail for some raison even after build has been successful
I think they might be linked.

image

and i get the following logs when I run the "failed" deployements

[2025-12-17 11:44:06] local.INFO: shopt -s expand_aliases
alias php=/usr/bin/php
export SITE_PATH=/home/vito/bun.errahmounispace.com
export DOMAIN=bun.errahmounispace.com
export BRANCH=main
export REPOSITORY=abdelhamiderrahmouni/bun-nextjs
export COMMIT_ID=5bc55ce85027ef9fa511dc7387467c0b5c12605a
export PHP_VERSION=
export PHP_PATH=/usr/bin/php
if ! cd /home/vito/bun.errahmounispace.com; then
    echo 'VITO_SSH_ERROR' && exit 1
fi

cd $SITE_PATH

git pull origin $BRANCH

bun install

bun --bun run build

sudo supervisorctl restart all

echo "✅ Deployment completed successfully!"
  
[2025-12-17 11:44:30] local.ERROR: Error executing command {"msg":"SSH command failed with an error","log":{"App\\Models\\ServerLog":{"server_id":3,"name":"3-1765971868-restart-workers.log","type":"restart-workers","disk":"server-logs","site_id":1,"updated_at":"2025-12-17T11:44:28.000000Z","created_at":"2025-12-17T11:44:28.000000Z","id":131}}} 

@abdelhamiderrahmouni
Copy link
Author

Just found the problem.

The Installation of bun when running their script curl -fsSL https://bun.sh/install | bash -s "bun-v${BUN_VERSION}" goes to /home/vito/.bun/bin/bun which is not globally accessible especially for supervisor's workers so the fix is to either specify the full path to bun when running it or installing it Globally.

what should we do ?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for Bun.js as a new runtime option for deploying JavaScript/TypeScript applications, following the same architectural patterns as the existing Node.js integration. The implementation includes service installation/uninstallation, site type registration, deployment scripts, and supervisor worker management. However, there are critical issues preventing workers from starting correctly, which aligns with the problem described in the PR description.

Key changes:

  • Adds Bun service handler for installing/uninstalling Bun runtime versions
  • Implements Bun site type for deploying Bun applications with git integration
  • Registers Bun in service and site type providers with version management

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
resources/views/ssh/services/bun/uninstall-bun.blade.php Shell script to remove Bun installation and clean up configuration files
resources/views/ssh/services/bun/install-bun.blade.php Shell script to install specific Bun versions via official installer
resources/deployment-scripts/bun.sh Deployment script for pulling code, installing dependencies, building, and restarting services
app/WorkflowActions/Site/CreateBunSite.php Workflow action defining inputs for creating Bun sites via API
app/SiteTypes/Bun.php Core site type handler implementing installation, vhost configuration, and base commands
app/Services/Bun/Bun.php Service handler managing Bun runtime installation, uninstallation, and version detection
app/Providers/SiteTypeServiceProvider.php Registers Bun site type with form fields for source control, port, repository, and branch
app/Providers/ServiceTypeServiceProvider.php Registers Bun service type with supported versions
app/Models/Server.php Adds methods to query installed Bun versions and retrieve Bun service instances

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 89 to 96
$this->site->server->ssh()->exec(
__('bun --cwd :path install', [
'path' => $this->site->path,
]),
'install-bun-dependencies',
$this->site->id
);
$this->site->server->ssh()->exec(
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSH commands are not being executed with the site user context. The NodeJS site type passes the user to ssh() like $this->site->server->ssh($this->site->user)->exec(...) to ensure commands run as the correct isolated user. Without this, the commands will run as the default SSH user, which can cause permission issues and defeats the isolation mechanism. The same issue exists on lines 96-102.

Suggested change
$this->site->server->ssh()->exec(
__('bun --cwd :path install', [
'path' => $this->site->path,
]),
'install-bun-dependencies',
$this->site->id
);
$this->site->server->ssh()->exec(
$this->site->server->ssh($this->site->user)->exec(
__('bun --cwd :path install', [
'path' => $this->site->path,
]),
'install-bun-dependencies',
$this->site->id
);
$this->site->server->ssh($this->site->user)->exec(

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +104
__('bun --bun run --cwd :path build', [
'path' => $this->site->path,
]),
'bun-build',
$this->site->id
);
$this->progress(65);
$command = __('bun --bun run --cwd :path start', [
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --bun flag is typically unnecessary for modern Bun versions and may cause compatibility issues. Bun automatically uses its own runtime by default. Consider simplifying the commands to bun run build and bun run start unless there's a specific reason to force the Bun runtime (e.g., when Node compatibility mode might otherwise be triggered). This would also make the commands more consistent with the install command which doesn't use --bun.

Suggested change
__('bun --bun run --cwd :path build', [
'path' => $this->site->path,
]),
'bun-build',
$this->site->id
);
$this->progress(65);
$command = __('bun --bun run --cwd :path start', [
__('bun run --cwd :path build', [
'path' => $this->site->path,
]),
'bun-build',
$this->site->id
);
$this->progress(65);
$command = __('bun run --cwd :path start', [

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the --bun flag is necessary as stated by the bun team because it forces bun to use itself instead of Nodejs for serving the application, this is especially true for Nextjs.

Comment on lines +11 to +12
# Verify installation
bun --version
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PATH exports are only effective within the current shell session and won't persist. The Bun installer (line 5) already handles adding Bun to shell configuration files. The exports on lines 8-9 are redundant and won't affect the verification command on line 12 unless they're in the same script context. To properly verify the installation, use the full path: $HOME/.bun/bin/bun --version instead of relying on the PATH exports.

Suggested change
# Verify installation
bun --version
# Verify installation using absolute path to avoid PATH issues
"$HOME/.bun/bin/bun" --version

Copilot uses AI. Check for mistakes.

bun install

bun --bun run build
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deployment script uses --bun flag inconsistently. Line 7 uses bun --bun run build while line 5 uses just bun install. For consistency and to avoid potential compatibility issues, either use the --bun flag for all commands or remove it entirely. Modern Bun versions don't require the --bun flag as they use their own runtime by default.

Suggested change
bun --bun run build
bun run build

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it is consistent, bun install is a particular command it does not need the --bun flag but the other commands like run dev, run build and run start need the --bun flag.

return trim($version);
}
}

Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line at end of file. The file should end with a single newline after the closing brace, not two blank lines. This is inconsistent with other service files like NodeJS.php.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +104 to +106
$command = __('bun --bun run --cwd :path start', [
'path' => $this->site->path,
]);
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worker command uses bun without the full path, but Bun is installed to $HOME/.bun/bin/bun which is not in supervisor's PATH. Unlike NodeJS which is installed system-wide via apt to /usr/bin/npm, Bun is installed per-user. Supervisor doesn't source shell configs where the Bun PATH is added. This is the root cause of workers getting stuck in "starting" state - supervisor cannot find the bun executable. The command should be changed to use the full path like /home/{user}/.bun/bin/bun --bun run --cwd :path start, where {user} is the site user. Alternatively, set the PATH environment variable in the supervisor config or install Bun system-wide.

Copilot uses AI. Check for mistakes.
BUN_VERSION={{ $version }}

# Install Bun using the official installer
curl -fsSL https://bun.sh/install | bash -s "bun-v${BUN_VERSION}"
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install-bun script downloads and executes remote code from https://bun.sh/install via curl | bash without any integrity verification or pinning. If the Bun installer endpoint or its TLS chain is compromised, this would let an attacker run arbitrary commands on every server where this installer is invoked. Consider installing Bun via a package manager or a locally stored, checksum-verified artifact, or at minimum verify the script’s integrity and pin to a specific, trusted version before executing it.

Copilot uses AI. Check for mistakes.
…t after it because it is different than `bun run dev`, `bun run build` ...etc
…al/bin instead of per user and clean up PATH entries.
@abdelhamiderrahmouni
Copy link
Author

I have just changed the installation to become global

added

# Move Bun binary to /usr/local/bin for global access
sudo mv ~/.bun/bin/bun /usr/local/bin/
sudo chmod a+x /usr/local/bin/bun

# The installation script adds  "~/.bun/bin" to $PATH in "~/.bashrc" automatically, we should remove it
sed -i '/\.bun\/bin/d' "$HOME/.bashrc" 2>/dev/null || true
sed -i '/\.bun\/bin/d' "$HOME/.zshrc" 2>/dev/null || true

and the bun worker works well now!

@abdelhamiderrahmouni
Copy link
Author

Installation still errors in isolated user case

bun install v1.3.4 (5eb2145b)

EACCES: Permission denied: could not create the "node_modules" directory (mkdir)

@abdelhamiderrahmouni
Copy link
Author

My bad I was using $this->site->server->ssh()->exec(...) to execute the install and build for bun dependencies, i had to use $this->site->server->ssh($this->site->user)->exec(...) to scope the execution to the isolated user. 🤦‍♂️

Now everything works well, just like with NodeJS.

@saeedvaziry
Copy link
Member

Since this is a plugin now, shall we close the PR?

@abdelhamiderrahmouni
Copy link
Author

Yes of course, Thank you so much @saeedvaziry .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants